#
# Makefile to facilitate tests and cleaning
#

HIDE := @
.FORCE:

.deps:
	$(HIDE)mkdir -p .deps

.deps/python.mk: makefilegen | .deps
	$(HIDE)./makefilegen python > .deps/python.mk

.deps/django.mk: makefilegen | .deps
	$(HIDE)./makefilegen django > .deps/django.mk

PYTHON_TESTS :=
include .deps/python.mk
DJANGO_TESTS :=
include .deps/django.mk

compile:
	$(HIDE)python manage.py compilemessages

build: .FORCE compile
	$(HIDE)find . -name \*.pyc | xargs rm -f
	$(HIDE)echo "Copying all production files to build directory"
	$(HIDE)./genbuild.sh

filecount: clean build
	$(HIDE)echo "File count: `find build | wc -l`"

%.pythontest:
	$(HIDE)echo "Testing $(subst .pythontest,.py,$@)"
	$(HIDE)python $(subst .pythontest,.py,$@)

%.djangotest:
	$(HIDE)echo "Testing $(subst .djangotest,,$@)"
	$(HIDE)python manage.py test $(subst .djangotest,,$@)

test: $(PYTHON_TESTS) $(DJANGO_TESTS)

MSG_IGNORES := \
    --ignore=autoload/* --ignore=build/* --ignore=dbindexer/* --ignore=django*
messages:
	python manage.py makemessages $(MSG_IGNORES) --all

clean:
	$(HIDE)echo "Removing *.deps files"
	$(HIDE)rm -rf .deps
	$(HIDE)echo "Cleaning *.pyc files"
	$(HIDE)find . -name \*.pyc | xargs rm -f
	$(HIDE)echo "Removing build directory"
	$(HIDE)rm -rf build

